<?php


$host = "0.0.0.0";
$port = 9999;
$listen_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($listen_socket, $host, $port);
socket_listen($listen_socket);

while (true) {
    $connection_socket = socket_accept($listen_socket);
    $pid = pcntl_fork();
    if ($pid==0){
        $msg = time()."hello123\r\n";
        socket_write($connection_socket, $msg, strlen($msg));
        echo time().":a new client".PHP_EOL;
        sleep(5);
        socket_close($connection_socket);
        exit;
    }
}

socket_close($listen_socket);

